<template>
  <div class="video-info">
    <!-- 作者信息和视频内容 -->
    <div class="content-wrapper">
      <!-- 作者信息 -->
      <div class="author-info" @click="goToUserProfile">
        <UserAvatar
          :user-id="video.author?.id"
          :avatar-url="video.author?.avatar"
          :username="video.author?.nickname"
          size="medium"
          :clickable="true"
          @click="goToUserProfile"
        />
        <div class="author-details">
          <div class="author-name">@{{ video.author?.nickname }}</div>
          <div class="video-time">{{ formatTime(video.createTime) }}</div>
        </div>
      </div>
      
      <!-- 视频信息 -->
      <div class="video-content">
        <div class="video-title" v-if="video.title">{{ video.title }}</div>
        <div v-if="video.description" class="video-description">
          {{ video.description }}
        </div>
        
        <!-- 话题标签 -->
        <div v-if="video.tags && video.tags.length" class="video-tags">
          <span v-for="tag in video.tags" :key="tag" class="tag">
            #{{ tag }}
          </span>
        </div>
        
        <!-- 音乐信息 -->
        <div v-if="video.musicInfo" class="music-info">
          <el-icon class="music-icon"><Headset /></el-icon>
          <span class="music-text">{{ video.musicInfo.name }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router'
import { formatTime } from '@/utils'
import { Headset } from '@element-plus/icons-vue'
import UserAvatar from '@/components/UserAvatar/index.vue'

const props = defineProps({
  video: {
    type: Object,
    required: true
  },
  videoIndex: {
    type: Number,
    required: true
  }
})

const router = useRouter()

// 跳转到用户主页
const goToUserProfile = () => {
  if (props.video.author?.id) {
    router.push(`/user/${props.video.author.id}`)
  }
}
</script>

<style lang="scss" scoped>
.video-info {
  position: absolute;
  bottom: 100px; // 给底部导航栏和操作按钮留空间
  left: 0;
  right: 80px; // 给右侧操作栏留空间
  padding: 20px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
  color: $text-white;
  z-index: 15;
  pointer-events: none; // 默认不拦截点击事件
  
  .content-wrapper {
    pointer-events: auto; // 恢复内容区域的点击事件
  }
  
  .author-info {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    cursor: pointer;
    transition: $transition-fast;
    
    &:hover {
      opacity: 0.8;
    }
    
    .author-details {
      flex: 1;
      
      .author-name {
        font-size: 16px;
        font-weight: 600;
        margin-bottom: 4px;
        color: $text-white;
      }
      
      .video-time {
        font-size: 12px;
        color: rgba(255, 255, 255, 0.7);
      }
    }
  }
  
  .video-content {
    .video-title {
      font-size: 16px;
      font-weight: 600;
      line-height: 1.4;
      margin-bottom: 8px;
      color: $text-white;
    }
    
    .video-description {
      font-size: 14px;
      line-height: 1.5;
      color: rgba(255, 255, 255, 0.9);
      max-height: 80px;
      overflow: hidden;
      display: -webkit-box;
      -webkit-line-clamp: 4;
      -webkit-box-orient: vertical;
      margin-bottom: 12px;
    }
    
    .video-tags {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      margin-bottom: 12px;
      
      .tag {
        background: rgba(255, 255, 255, 0.1);
        color: $text-white;
        padding: 4px 8px;
        border-radius: 12px;
        font-size: 12px;
        font-weight: 500;
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.1);
      }
    }
    
    .music-info {
      display: flex;
      align-items: center;
      gap: 8px;
      background: rgba(255, 255, 255, 0.1);
      padding: 8px 12px;
      border-radius: 20px;
      backdrop-filter: blur(10px);
      border: 1px solid rgba(255, 255, 255, 0.1);
      max-width: fit-content;
      
      .music-icon {
        color: $text-white;
        font-size: 16px;
      }
      
      .music-text {
        font-size: 12px;
        color: $text-white;
        font-weight: 500;
        max-width: 200px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
  }
}

// 适配不同屏幕尺寸
@media (max-width: 768px) {
  .video-info {
    bottom: 80px;
    right: 70px; // 为移动端右侧操作栏预留更少空间
    padding: 16px;
    
    .author-info {
      margin-bottom: 12px;
      
      .author-details {
        .author-name {
          font-size: 15px;
        }
        
        .video-time {
          font-size: 11px;
        }
      }
    }
    
    .video-content {
      .video-title {
        font-size: 15px;
      }
      
      .video-description {
        font-size: 13px;
        max-height: 60px;
        -webkit-line-clamp: 3;
      }
      
      .video-tags .tag {
        font-size: 11px;
        padding: 3px 6px;
      }
      
      .music-info {
        padding: 6px 10px;
        
        .music-icon {
          font-size: 14px;
        }
        
        .music-text {
          font-size: 11px;
          max-width: 150px;
        }
      }
    }
  }
}

@media (max-width: 480px) {
  .video-info {
    bottom: 70px;
    right: 60px;
    padding: 12px;
    
    .video-content {
      .video-description {
        max-height: 45px;
        -webkit-line-clamp: 2;
      }
    }
  }
}
</style> 